package cn.fintecher.pangolin.service.manage.request;

import cn.fintecher.pangolin.common.enums.BaseSelect;
import cn.fintecher.pangolin.common.enums.BaseStatus;
import cn.fintecher.pangolin.entity.mysql.QRole;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.Objects;

/**
 * @Auther: xiaqun
 * @Description: 角色查询条件
 * @Date: 19:10 2019/8/14
 */

@Data
public class FindRoleRequest {
    @ApiModelProperty(value = "角色名字")
    private String name;

    @ApiModelProperty(value = "状态")
    private BaseStatus status;

    public BooleanBuilder getBuilder() {
        BooleanBuilder builder = new BooleanBuilder();
        QRole qRole = QRole.role;
        builder.and(qRole.isSystem.eq(BaseSelect.NO));
        if (StringUtils.isNotBlank(this.name)) {
            builder.and(qRole.name.like("%" + StringUtils.trim(this.name) + "%"));
        }
        if (Objects.nonNull(status)) {
            builder.and(qRole.status.eq(status));
        }
        return builder;
    }
}
